<?php

use Illuminate\Database\Seeder;
use App\Models\SettingDocument;
class SettingDocumentTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $typeList = SettingDocument::documentType();
        $channel_list = \App\Models\SettingChannel::$CHANNEL_LIST;
        $insertData = array();
        $insertDataTrue = array();
        foreach ($typeList as $k => $v){
            $document_name = isset(SettingDocument::$DOCUMENT_LIST[$k]) ? SettingDocument::$DOCUMENT_LIST[$k] : '';
            $url_set = $v['url_set'];
            if(!$v['is_channel_code']){
                $data = array();
                $data['type'] = $k;
                $data['document_name'] = $document_name;
                $data['document_content'] = json_encode([['name'=>$document_name,'content' => '']],JSON_UNESCAPED_UNICODE);
                $data['url_set'] = $url_set;
                $insertData[] = $data;
            }else{
                foreach ($channel_list as $key => $val){
                    $data = array();
                    $data['type'] = $k;
                    $data['channel_code'] = $key;
                    $data['document_name'] = $document_name;
                    $data['document_content'] = json_encode([['name'=>$document_name,'content' => '']],JSON_UNESCAPED_UNICODE);;
                    $data['url_set'] = $url_set;
                    $insertDataTrue[] = $data;
                }

            }
        }
        DB::table('setting_documents') -> insert($insertData);
        DB::table('setting_documents') -> insert($insertDataTrue);
    }
}
